
package com.baidu.a.a.a.a.a;

import java.io.UnsupportedEncodingException;

public final class b {
    private static final byte[] a = new byte[]{65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47};

    public static byte[] a(byte[] var0) {
        return a(var0, var0.length);
    }

    public static byte[] a(byte[] var0, int var1) {
        int var2;
        if((var2 = var1 / 4 * 3) == 0) {
            return new byte[0];
        } else {
            byte[] var9 = new byte[var2];
            int var3 = 0;

            while(true) {
                byte var4;
                if((var4 = var0[var1 - 1]) != 10 && var4 != 13 && var4 != 32 && var4 != 9) {
                    if(var4 != 61) {
                        int var5 = 0;
                        int var6 = 0;
                        boolean var10 = false;
                        int var7 = 0;

                        for(int var8 = 0; var8 < var1; ++var8) {
                            if((var4 = var0[var8]) != 10 && var4 != 13 && var4 != 32 && var4 != 9) {
                                int var11;
                                if(var4 >= 65 && var4 <= 90) {
                                    var11 = var4 - 65;
                                } else if(var4 >= 97 && var4 <= 122) {
                                    var11 = var4 - 71;
                                } else if(var4 >= 48 && var4 <= 57) {
                                    var11 = var4 + 4;
                                } else if(var4 == 43) {
                                    var11 = 62;
                                } else {
                                    if(var4 != 47) {
                                        return null;
                                    }

                                    var11 = 63;
                                }

                                var7 = var7 << 6 | (byte)var11;
                                if(var6 % 4 == 3) {
                                    var9[var5++] = (byte)(var7 >> 16 & 255);
                                    var9[var5++] = (byte)(var7 >> 8 & 255);
                                    var9[var5++] = (byte)var7;
                                }

                                ++var6;
                            }
                        }

                        if(var3 > 0) {
                            var7 <<= var3 * 6;
                            var9[var5++] = (byte)(var7 >> 16 & 255);
                            if(var3 == 1) {
                                var9[var5++] = (byte)(var7 >> 8 & 255);
                            }
                        }

                        byte[] var12 = new byte[var5];
                        System.arraycopy(var9, 0, var12, 0, var5);
                        return var12;
                    }

                    ++var3;
                }

                --var1;
            }
        }
    }

    public static String a(byte[] var0, String var1) throws UnsupportedEncodingException {
        int var2;
        byte[] var7 = new byte[(var2 = (var0.length << 2) / 3) + var2 / 76 + 3];
        int var3 = 0;
        int var5 = 0;
        int var6 = var0.length - var0.length % 3;

        for(int var4 = 0; var4 < var6; var4 += 3) {
            var7[var3++] = a[(var0[var4] & 255) >> 2];
            var7[var3++] = a[(var0[var4] & 3) << 4 | (var0[var4 + 1] & 255) >> 4];
            var7[var3++] = a[(var0[var4 + 1] & 15) << 2 | (var0[var4 + 2] & 255) >> 6];
            var7[var3++] = a[var0[var4 + 2] & 63];
            if((var3 - var5) % 76 == 0 && var3 != 0) {
                var7[var3++] = 10;
                ++var5;
            }
        }

        switch(var0.length % 3) {
            case 1:
                var7[var3++] = a[(var0[var6] & 255) >> 2];
                var7[var3++] = a[(var0[var6] & 3) << 4];
                var7[var3++] = 61;
                var7[var3++] = 61;
                break;
            case 2:
                var7[var3++] = a[(var0[var6] & 255) >> 2];
                var7[var3++] = a[(var0[var6] & 3) << 4 | (var0[var6 + 1] & 255) >> 4];
                var7[var3++] = a[(var0[var6 + 1] & 15) << 2];
                var7[var3++] = 61;
        }

        return new String(var7, 0, var3, var1);
    }
}
